 <?php 
 include('../../Connections/KRAPPERCON.php');
 
 $oper = $_POST['oper'];
 
 if ($oper == 'view'){
 $f1 = $_POST['fini'];
 $f2 = $_POST['ffin'];
 
 if ( ! ( date("m",strtotime($f1)) == date("m",strtotime($f2)) 
 		&&   date("Y",strtotime($f1)) == date("Y",strtotime($f2))  ) ) {
		echo "<script type='text/javascript'>showOk('Debe indicar dos fechas dentro del mismo Año/Mes');</script>";
		return;
		}
 
 $sql = "call sp_getMonthResult('".$f1."','".$f2."');";
 $res = $mysqli->query($sql);
 doEcho($sql);
 if ($res){
 	if ($row = $res->fetch_assoc()){
	
	$vta_contado = rnd($row['w_vtacon']);
	$vta_credito = rnd($row['w_vtacre']);
	$gst_adminis = rnd($row['w_gstadm']);
	$gst_ventas = rnd($row['w_gstvta']);
	$imp_ley = rnd($row['w_impley']);
	$imp_rta = rnd($row['w_imprta']);
	$igv_compras = rnd($row['w_igvcom']);
	$igv_ventas = rnd($row['w_igvvta']);
	
	$retencion = $row['w_reten'];
	$detraccion = $row['w_detra'];
	
	$ing_totales = $vta_contado + $vta_credito;
	$cst_ventas = $row['w_cstven'];
	$uti_bruta = $ing_totales - $cst_ventas;
	
	$gst_operacionales = $gst_adminis + $gst_ventas;
	$uti_operativa = $uti_bruta - $gst_operacionales;
	
	$gst_finan = $row['w_gstfin'];
	
	$res_operacional = $uti_operativa;
		
	$uti_antes_ir = $uti_operativa - $gst_finan;
	
	$imp_rta = ( 1.5 * 0.01 ) * $ing_totales;
	
	$gst_tributarios = $igv_ventas + $imp_rta;		
	
	$uti_neta = $uti_antes_ir - $gst_tributarios;
	
 ?>
 
<table width="100%" rules="all" border="1" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
        <th scope="row">Concepto</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
      </tr>
  </thead>
      <tr>
        <td><strong>Ingresos Totales</strong></td>
        <td class="qt"><strong><?php echo rnd($ing_totales); ?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;&nbsp;Ventas al Contado</td>
        <td class="qt"><?php echo rnd($vta_contado);?></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;&nbsp;Ventas al Crédito</td>
        <td class="qt"><?php echo rnd($vta_credito);?></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>Costos de las Ventas</strong></td>
        <td class="qt"><strong><?php echo rnd($cst_ventas);?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;&nbsp;Costo de las Ventas</td>
        <td class="qt"><?php echo rnd($cst_ventas);?></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>Utilidad Bruta</strong></td>
        <td class="qt"><strong><?php echo rnd($uti_bruta);?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>Gastos Operacionales</strong></td>
        <td class="qt"><strong><?php echo rnd($gst_operacionales);?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;&nbsp;Gastos Administrativos</td>
        <td class="qt"><?php echo rnd($gst_adminis);?></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td> &nbsp;&nbsp;Gastos de Ventas</td>
        <td class="qt"><?php echo rnd($gst_ventas);?></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>Utilidad Operativa</strong></td>
        <td class="qt"><strong><?php echo rnd($uti_operativa);?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>RESULTADO OPERACIONAL</strong></td>
        <td class="qt"><strong><?php echo rnd($res_operacional);?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>GASTOS FINANCIEROS</strong></td>
        <td class="qt"><strong><?php echo rnd($gst_finan);?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>UTILIDAD ANTES DE IR</strong></td>
        <td class="qt"><strong><?php echo rnd($uti_antes_ir);?></strong></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;&nbsp;Impuesto a la Renta (30%)</td>
        <td class="qt"><?php echo rnd($imp_rta);?></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><strong>UTILIDAD NETA</strong></td>
        <td class="qt"><strong><?php  echo rnd($uti_neta);?></strong></td>
        <td>&nbsp;</td>
      </tr>
</table>
<?php 
	}
	$res->close();
	$mysqli->check_result();
	}
	
}

?>